@extends('car.base.shopping')
@section('content')
@section('content1')
<form action="shopping" method="get">
    <input type="text" placeholder="请输入商品名称" name="name">
    <button>搜索</button>
</form>
    
@stop
    
    <!--内容开始-->
    <div class="payment-interface w1200">
    	<div class="pay-info">
        <form action="{{ url('car/pay/') }}" method="get" name="pay">
         <input type="hidden" name="sum_price" value="{{ $sum_price }}">
         <input type="hidden" name="order_id" value="1">
         <input type="hidden" name="reveive_address_id" value="1">
        <input type="hidden" name="_token" value="{{ csrf_token() }}">
        	<div class="info-tit">
            	<h3>选择收货地址</h3>
            </div>
            <ul class="pay-dz" id="address">
                
            </ul>
            <P class="pay-xgdz">修改地址和使用新地址样式一样。</P>
            <button class="pay-xdz-btn" type="button" onclick="demo();">使用新地址</button>
        </div>
        <div class="pay-info">
        	<div class="info-tit" style="border-bottom:0;">
            	<h3>订单信息</h3>
            </div>
        </div>
        <div class="cart-con-info">
        	<div class="cart-con-tit" style="margin:20px 0 5px;">
                <p class="p2" style="width:90px;"></p>
                <p class="p2" style="width:190px;">图片</p>
                <p class="p7" style="width:210px;">描述</p>
                <p class="p4" style="width:70px;">数量</p>
                <p class="p8" style="width:75px;">运费</p>
                <p class="p5">单价（元）</p>
                <p class="p6" style="width:173px;">金额（元）</p>
            </div>
         @foreach ($list as $v)
            <div class="info-mid">
                <h3 class="f-r">订单号：{{ $v[0]->id }}</h3>
                <div class="mid-tu f-l">
                	<a href="#"><img src="{{ asset('images') }}/{{ $v[0]->product_pic }}" /></a>
                </div>
                <div class="mid-font f-l" style="margin-right:40px;">
                	<a href="#">{{ $v[0]->description }}</a>
                </div>
                <div class="mid-sl f-l" style="margin:10px 54px 0px 0px;">
                	
                <p style="font-size:19px;color:green;">{{ $v[0]->product_num }}</p>
                    
                </div>
                <p class="mid-yunfei f-l">¥ 0.00</p>
                <p class="mid-dj f-l">{{ $v[0]->lower_price }}.00</p>
                <p class="mid-je f-l" style="margin:10px 120px 0px 0px;">{{ $v[0]->total_price }}</p>
                <div class="mid-chaozuo f-l">
                	
                </div>
                <div style="clear:both;"></div>
            </div>
        @endforeach
            <div class="info-heji">
                <p class="f-r">店铺合计(含运费)：<span>¥46.60</span></p>
            </div>
            <div class="info-tijiao">
            	<p class="p2">
                	您共有积分<span>460</span>可抵<span>4.6元</span>
                    <a href="#">使用</a>
                </p>            	
            	<p class="p1">实付款：<span>{{ $sum_price }}</span></p>
                <button class="btn" id="tijiao">提交订单</button>
            </div>
            </form>
        </div>
    </div>
    <script type="text/javascript">
    //获取订单id号
            alert("数据提交中...");
        var order_id = '';
        var product_id = '';
        @foreach ($list as $v)
            order_id += {{ $v[0]->id }}+',';
        @endforeach
        $('input[name="order_id"]').attr('value',order_id);
        console.log(order_id);
    //表单提交事件
        $('#tijiao').click(function() {
            var pay = document.pay;
            pay.action = 'pay/';
            pay.submit();
        });
    //获取产品id号，带到修改地址页面
        @foreach ($list as $v)
            product_id += {{ $v[0]->id }}+',';
        @endforeach
        console.log(product_id);
        function demo(){
            window.location='/car/order/createaddress/'+product_id;
        }
        //ajax遍历数据库用户填写的所有地址
        var url = "{{ url('car/aja/user_id') }}";
        var user_id = {{ $list[0][0]->user_id }}
        $.ajax({
            url:url,
            async:false,                //是否异步
            type:'get',                 //请求方式
            data:{user_id:user_id},              //发送的数据
            dataType:'json',            //响应的数据类型
            error:function()            //失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)      //成功时回调函数
            {
                for(i=0;i<data.length;i++){
                    $('#address').append('<li><h3><span class="sp2">地址编号<span>'+data[i].id+'</span></span><br><span class="sp1">'+data[i].province+'</span>（<span class="sp3">'+data[i].receive_name+'</span> 收）</h3><p><span class="sp1">'+data[i].address+'</span><span class="sp2">'+data[i].telephone+'</span></p> <a href="JavaScript:;" xiugai="">修改</a></li>');

               }
                $('#address').append('<div style="clear:both;"></div>');
                
            }
        });
        var reveive_address_id = '';
        $('li').each(function() {
            $(this).click(function() {
               reveive_address_id = $(this).children().children().children().html();
               console.log(reveive_address_id);
               $('input[name="reveive_address_id"]').attr('value',reveive_address_id);
            });
        });
        
    </script>
    
    <!--底部一块-->
   @stop
